//
//  Cost.hpp
//  newAR
//
//  Created by CADCG on 4/7/16.
//  Copyright © 2016 Shangjin Zhai. All rights reserved.
//

#ifndef Cost_hpp
#define Cost_hpp

#include <stdio.h>
#include <Algorithm>
namespace Optimise {
    
    
    
    
    
template<typename TYPE>
double computeSSD(TYPE* a,TYPE* b,int length);

template<typename _ForwardIterator1,
         typename _ForwardIterator2,
         typename _Predicate>
double computeSSD(const _ForwardIterator1&first1,const _ForwardIterator1&last1,
                  const _ForwardIterator2&first2,const _ForwardIterator2&last2,
                  _Predicate compute);
  

//This function may cause overflow if the type is unsigned type.
template<typename TYPE>
double computeSSD(TYPE* a,TYPE* b,int length)
{
  double err=0;
  for(int i=0;i<length;i++)
  {
    err+=(a[i]-b[i])*(a[i]-b[i]);
  }
  return err;
}
    
    
    
}









#endif /* Cost_hpp */
